<?php
if (get_template_type() == 'index') {
    ?>
    <style>
        div.search_condition section dl dd.list a.sel{
            color:#f60;
        }
        .list .selected{
            font-weight: 600;
            line-height: 20px;
            color: #999;
            background-color: #FFF;
            display: inline-block;
            height: 20px;
            padding: 0 0 0 5px;
            margin-right: 5px;
            border: solid 1px #D7D7D7;
            cursor: pointer;
        }
        .list .selected em {
            line-height: 20px;
            color: #f60;
            background-color: #FFF;
            vertical-align: top;
            display: inline-block;
            height: 20px;
            padding: 0 2px;
            margin-left: 2px;
        }
        .list .selected i {
            font-family: Verdana;
            line-height: 20px;
            color: #CCC;
            vertical-align: top;
            text-align: center;
            display: inline-block;
            width: 20px;
            height: 20px;
        }
        .list .selected:hover {
            border-color: #f60;
        }
        div.search_condition{
            margin-top: 10px;
        }
        .all{
            vertical-align: top;
            width: 100px;
            text-align: right;
            display: inline-block;
        }
        .height_auto li{
            display: block !important;
        }
    </style>
    <div class="search_condition">
        <section>
            <?php if ((isset($output['checked_brand']) && is_array($output['checked_brand'])) || (isset($output['checked_attr']) && is_array($output['checked_attr']))) { ?>
                <dl nc_type="ul_filter">
                    <dt><?php echo $lang['goods_class_index_selected'] . $lang['nc_colon']; ?></dt>
                    <dd class="list">
                        <?php if (isset($output['checked_brand']) && is_array($output['checked_brand'])) { ?>
                            <?php foreach ($output['checked_brand'] as $key => $val) { ?>
                                <span class="selected"
                                      nctype="span_filter"><?php echo $lang['goods_class_index_brand']; ?>
                                    :<em><?php echo $val['brand_name'] ?></em><i
                                        data-uri="<?php echo removeParam(array('b_id' => $key)); ?>">X</i></span>
                            <?php } ?>
                        <?php } ?>
                        <?php if (isset($output['checked_attr']) && is_array($output['checked_attr'])) { ?>
                            <?php foreach ($output['checked_attr'] as $val) { ?>
                                <span class="selected"
                                      nctype="span_filter"><?php echo $val['attr_name'] . ':<em>' . $val['attr_value_name'] . '</em>' ?>
                                    <i data-uri="<?php echo removeParam(array('a_id' => $val['attr_value_id'])); ?>">X</i></span>
                            <?php } ?>
                        <?php } ?>
                    </dd>
                </dl>
            <?php } ?>
            <?php
            if($_GET['act'] == 'brand' && $_GET['op'] == 'list'){
                ?>
                <style>
                    div.goods_list{
                        margin-top: 15px;
                    }
                </style>
                <?php
            }


            if($_GET['act'] != 'brand' && $_GET['op'] != 'show_place'){
                $kw = $_GET['keyword'];
                unset($_GET['keyword']);
                $result = array();

                if (!isset($_GET['cate_id'])) {
                    $_GET['cate_id'] = 0;
                }
                $cate_id = $_GET['cate_id'];

                $arr = array();
                $pids = array();

                //查找当前分类的父分类
                while($cate_id != 0){
                    $list = Model('goods_class')->getGoodsClassInfoById($cate_id);
                    $children = Model('goods_class')->getGoodsClassListByParentId($cate_id);
                    if($children){
                        $result[] = $children;
                        $arr[] = $cate_id;
                    }
                    $cate_id = $list['gc_parent_id'];
                    $pids[] = $cate_id;
                }
                $result[] = Model('goods_class')->getGoodsClassListByParentId(0);

                $result = array_reverse($result);
                $arr = array_reverse($arr);
                $pids = array_reverse($pids);
                $pids[] = $_GET['cate_id'];

//                //查找当前分类的子分类
//                $result[] = Model('goods_class')->getGoodsClassListByParentId($_GET['cate_id']);

                $last = 0;

                foreach($result as $pid =>  $cats){
                ?>
            <dl class="search_cats">

                <dt>分类：</dt>
                <dd class="list">
                    <?php

                    ?>
                    <a class="all_" <?php if(false){?>class="sel"<?php }?> href="/shop/?act=search&op=index&cate_id=<?php echo $pids[$pid];?>">全部</a>
                    <?php
//                    $all_cates =
                    foreach ($cats as $cat) {
                        ?>
                        <a <?php if($_GET['cate_id'] == $cat['gc_id'] || in_array($cat['gc_id'],$arr)){?>class="sel"<?php }?> href="<?php  echo replaceParam(array('cate_id'=>$cat['gc_id']));?>"><?php echo $cat['gc_name'] ?></a>
                        <?php
                    }
                    ?>
                </dd>

                <dd class="more">
                    <a href="javascript:;">更多<code>></code></a>
                </dd>
            </dl>
                    <?php }?>
                <script>
                    $('.search_cats').each(function () {
                        if($(this).find(".sel").length == 0) {
                            $(this).find('.all_').addClass('sel');
                        }
                    })
                </script>
            <?php
                $_GET['keyword'] = $kw;
            ?>
            <?php }?>
            <?php
            $brand_list = Model('goods_class')->get_class_binding_brand($_GET['cate_id']);
            if(!empty($brand_list)){
                $brand = array();
                foreach ($brand_list as $k => $v) {
                    $brand[$v['brand_id']] = $v;
                }

            ?>
            <dl>
                <dt>品牌：</dt>
                <dd class="list">
                <a <?php if($_GET['b_id'] == 0){?>class="sel"<?php }?> href="<?php $bid = $_GET['b_id']; echo removeParam(array('b_id'=>$bid));?>">全部</a>
                <?php
                    foreach ($brand as $key => $value) {
                        // echo $k;
                ?>
                    <a <?php if($_GET['b_id'] == $key){?>class="sel"<?php }?> href="<?php
                    // $b_id = (($_GET['b_id'] != '' && intval($_GET['b_id']) != 0) ? $_GET['b_id'] . '_' . $k : $k);
                    echo replaceParam(array('b_id'=>$key));?>"><?php echo $value['brand_name'];?></a>
                <?php }?>
                </dd>
                <dd class="more">
                    <a href="javascript:;">更多<code>></code></a>
                </dd>
            </dl>
            <?php //print_r($output['attr_array']);exit;?>
            <?php if (false && !empty($output['attr_array']) && is_array($output['attr_array'])) { ?>
                <?php $j = 0;
                foreach ($output['attr_array'] as $key => $val) {
                    $j++; ?>
                    <?php if (!isset($output['checked_attr'][$key]) && !empty($val['value']) && is_array($val['value'])) { ?>
                        <dl>
                            <dt><?php echo $val['name'] . $lang['nc_colon']; ?></dt>
                            <dd class="list">
                                <ul>
                                    <!-- <li>
                                        <a <?php if($_GET['a_id'] == 0){?>class="sel"<?php }?> href="<?php echo replaceParam(array('a_id' => $$_GET['a_id']));?>">全部</a>
                                    </li> -->
                                    <?php $i = 0;
                                    foreach ($val['value'] as $k => $v) {
                                        $i++; ?>
                                        <li <?php if ($i > 10){ ?>style="display:none"
                                            nc_type="none"<?php } ?>><a
                                                <?php if($_GET['a_id'] == $v['attr_value_id']){?>class="sel"<?php }?> href="<?php
                                                 $a_id = (($_GET['a_id'] != '' && $_GET['a_id'] != 0) ? $_GET['a_id'] . '_' . $k : $k);
                                                echo replaceParam(array('a_id' => $a_id)); ?>"><?php echo $v['attr_value_name']; ?></a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            </dd>
                            <?php if (count($val['value']) > 10) { ?>
                                <dd class="more"><a href="javascript:;" nc_type="show">
                                        <?php echo $lang['goods_class_index_more']; ?></a>
                                    <code>></code>
                                </dd>
                            <?php } ?>
                        </dl>
                    <?php } ?>
                    <?php $dl++;
                } ?>
            <?php } ?>

            <?php }?>
            <dl>
                <dt>排序：</dt>
                <style>
                    dd.list span{
                        margin-left: 5px;
                    }
                </style>
                <dd class="list">
                    <b <?php if(!$_GET['key']){?>class="sel"<?php }?>><a
                            href='<?php echo dropParam(array('order', 'key'));?>'>默认</a>
                    </b>
                    <b <?php if($_GET['key'] == '3'){?>class="sel"<?php }?>><a href="<?php echo ($_GET['order'] == '2' && $_GET['key'] == '3') ? replaceParam(array('key' => '3', 'order' => '1')):replaceParam(array('key' => '3', 'order' => '2')); ?>" <?php if($_GET['key'] == '3'){?>class="<?php echo $_GET['order'] == 1 ? 'up' : 'down';?>"<?php }?> title="<?php echo ($_GET['order'] == '2' && $_GET['key'] == '3')?$lang['goods_class_index_price_asc']:$lang['goods_class_index_price_desc']; ?>"><?php echo $lang['goods_class_index_price'];?><span
                                <?php
                                if($_GET['order'] == 1 && $_GET['key'] == 3){
                                    echo "class='icon icon-angle-up'";
                                }
                                else if($_GET['order'] == 2 && $_GET['key'] == 3){
                                    echo "class='icon icon-angle-down'";
                                }
                                ?>
                            ></span></a></b>
                    <b <?php if($_GET['key'] == '1'){?>class="sel"<?php }?>><a href="<?php echo ($_GET['order'] == '2' && $_GET['key'] == '1') ? replaceParam(array('key' => '1', 'order' => '1')):replaceParam(array('key' => '1', 'order' => '2')); ?>" <?php if($_GET['key'] == '1'){?>class="<?php echo $_GET['order'] == 1 ? 'up' : 'down';?>"<?php }?> title="<?php echo ($_GET['order'] == '2' && $_GET['key'] == '1')?$lang['goods_class_index_sold_asc']:$lang['goods_class_index_sold_desc']; ?>"><?php echo $lang['goods_class_index_sold'];?><span
                                <?php
                                if($_GET['order'] == 1 && $_GET['key'] == 1){
                                    echo "class='icon icon-angle-up'";
                                }
                                else if($_GET['order'] == 2 && $_GET['key'] == 1){
                                    echo "class='icon icon-angle-down'";
                                }
                                ?>
                            ></span></a></b>
                    <b <?php if($_GET['key'] == '2'){?>class="sel"<?php }?>><a href="<?php echo ($_GET['order'] == '2' && $_GET['key'] == '2') ? replaceParam(array('key' => '2', 'order' => '1')):replaceParam(array('key' => '2', 'order' => '2')); ?>" <?php if($_GET['key'] == '2'){?>class="<?php echo $_GET['order'] == 1 ? 'up' : 'down';?>"<?php }?> title="<?php  echo ($_GET['order'] == '2' && $_GET['key'] == '2')?$lang['goods_class_index_click_asc']:$lang['goods_class_index_click_desc']; ?>"><?php echo $lang['goods_class_index_click']?><span
                                <?php
                                if($_GET['order'] == 1 && $_GET['key'] == 2){
                                    echo "class='icon icon-angle-up'";
                                }
                                else if($_GET['order'] == 2 && $_GET['key'] == 2){
                                    echo "class='icon icon-angle-down'";
                                }
                                ?>
                            ></span></a></b>
                </dd>
            </dl>
        </section>
    </div>
    <style>
        .nch-breadcrumb a{
            color: #333;
        }
        .nch-breadcrumb span{
            color:#333;
        }
        .nch-breadcrumb a:hover{
            color:#ff6800;
        }
        .goods_list section.f4{
            height: auto;
        }
        .clear{
            display: block;
            content: "";
            clear: both;
        }
    </style>
    <div class="nch-breadcrumb-layout">
        <div class="nch-breadcrumb wrapper">
            <span><a href="/shop">首页</a></span>
            <span class="arrow">&gt;</span>
            <span>所有商品</span>
        </div>
    </div>
    <!-- <div class="wrapper navbar">
        <a href="">首页</a>
        <code> > </code>
        <a href="">所有商品</a>
    </div> -->
    <style>
        ._con_add{
            position: relative;
            float: left;
            width: 110px;
            height:40px;
            line-height: 40px;
            text-align:center;
            background:#6eb595;
            color:#fff;
            font-size: 14px;
            top:1px;
            display:none
        }
        ._addcart{
            left:1px;
        }
        ._collect{
            /*right: 1px;*/
            margin-left: 9px;
        }
        .icon-plus-sign{
            color:#fff;
        }
        ._con_add a{
            color:#fff;
        }
        ._con_add a:hover{
            text-decoration: none;
        }
        ._item_on ._con_add{
            display: block;
        }
        /*._f2._collect{
            margin-left: 16px;
        }
        .f4 ._collect{
            margin-left: 16px !important;
        }*/
    </style>
    <?php
    $goods_list = &$output['goods_list'];
    ?>
    <div class="goods_list wrapper">

        <?php
        if (empty($goods_list)) {
        ?>
            <div style="width: 100%;height: 320px;line-height: 320px;text-align: center;background: #fff;font-size: 16px;">
                <h2>
                    没有检索到符合条件的商品
                </h2>
            </div>
        <?php
        }
        ?>

        <section class="f1" style="display: none;">
            <?php
            for ($i = 0; $i < -1 && $i < count($goods_list); $i++) {
                ?>
                <section class="item">
                    <div style="height:20px;position:relative;"></div>
                    <div class="_addcart_hover" style="height: 60px;position:absolute;top:-60px;">
                    <div class="_con_add _addcart" onclick="addcart(<?php echo $goods_list[$i]['goods_id'];?>,1,'addcart_callback');">
                        <i class="icon-plus-sign">

                        </i>
                        <a href="javascript:;">购物袋</a>

                    </div>
                    <div class="_con_add _collect" onclick="collect_goods(<?php echo $goods_list[$i]['goods_id'];?>,'count','goods_collect');">
                        <i class="icon-star-empty">

                        </i><a href="javascript:;">收藏</a>
                    </div>
                    </div>
                    <a href="<?php echo urlShop('goods', 'index', array('goods_id' => $goods_list[$i]['goods_id'])); ?>"
                       class="img">
                        <img src="<?php echo thumb($goods_list[$i], 240, 1) ?>" alt="">
                    </a>

                    <div class="name">
                        <p>
                            <b><?php echo $goods_list[$i]['goods_name'] ?></b>
                        </p>

                        <p>
                            <span>
                            <?php
                            echo $goods_list[$i]['goods_jingle'];
                            ?>
                            </span>
                        </p>

                    </div>
                    <div class="price">
                        ￥
                        <?php
                        echo $goods_list[$i]['goods_price'];
                        ?>
                    </div>
                </section>
                <?php
            }
            ?>
        </section>
        <script>
            $(function(){
                $('.item').hover(function(){
                    $(this).find('._addcart_hover').animate({top:"0"});
                },function(){
                    $(this).find('._addcart_hover').animate({top:"-60px"});
                })
            })
        </script>
        <style>
            ._f2{
                width: 140px;
            }
            ._f3{
                width: 144px;
            }
        </style>
        <section class="f2">
            <?php


            for ($i = 0; $i < count($goods_list); $i++) {
            ?>
                <section class="item" style="margin-bottom: 10px;">
                    <div style="height:10px;position:relative;"></div>
                    <div class="_addcart_hover" style="height: 60px;position:absolute;top:-60px;">
                        <div class="_con_add _f2 _addcart" onclick="addcart(<?php echo $goods_list[$i]['goods_id'];?>,1,'addcart_callback');">
                            <i class="icon-plus-sign">

                        </i>
                        <a href="javascript:;">购物袋</a>
                        </div>
                        <div class="_con_add _f2 _collect" onclick="collect_goods(<?php echo $goods_list[$i]['goods_id'];?>,'count','goods_collect');">
                            <i class="icon-star-empty">
                        </i>
                        <a href="javascript:;">收藏</a>
                        </div>
                    </div>
                    <a href="<?php echo urlShop('goods', 'index', array('goods_id' => $goods_list[$i]['goods_id'])); ?>"
                       class="img">
                        <img src="<?php echo thumb($goods_list[$i], 240, 1) ?>" alt="">
                    </a>

                    <div class="name">
                        <p>
                            <b><?php echo $goods_list[$i]['goods_name'] ?></b>
                        </p>

                        <p>
                            <span>
                            <?php
                            echo $goods_list[$i]['goods_jingle'];
                            ?>
                            </span>
                        </p>
                
                    </div>
                    <div class="discount">
                        <?php if ($goods_list[$i]["is_discount"]) { ?>
                        <span>限时折扣</span>
                        <?php } ?>
                    </div>
                    <div class="price">
                        ￥
                        <?php
                        echo $goods_list[$i]['goods_price'];
                        ?>
                    </div>
                </section>
            <?php
            }
            ?>
        </section>

        <section class="f3">
            <?php
            for ($i = 9; $i < -1 && $i < count($goods_list); $i++) {
                ?>
                <section class="item">
                    <div style="height:10px;position:relative;"></div>
                    <div class="_addcart_hover" style="height: 60px;position:absolute;top:-60px;" onclick="addcart(<?php echo $goods_list[$i]['goods_id'];?>,1,'addcart_callback');">
                        <div class="_con_add _f3 _addcart">
                                <i class="icon-plus-sign">

                            </i>
                            <a href="javascript:;">购物袋</a>
                            </div>
                            <div class="_con_add _f3 _collect" onclick="collect_goods(<?php echo $goods_list[$i]['goods_id'];?>,'count','goods_collect');">
                                <i class="icon-star-empty">
                            </i>
                            <a href="javascript:;">收藏</a>
                        </div>
                    </div>
                    <a href="<?php echo urlShop('goods', 'index', array('goods_id' => $goods_list[$i]['goods_id'])); ?>"
                       class="img">
                        <img src="<?php echo thumb($goods_list[$i], 240, 1) ?>" alt="">
                    </a>

                    <div class="name">
                        <p>
                            <b><?php echo $goods_list[$i]['goods_name'] ?></b>
                        </p>

                        <p>
                            <span>
                            <?php
                            echo $goods_list[$i]['goods_jingle'];
                            ?>
                            </span>
                        </p>

                    </div>
                    <div class="price">
                        ￥
                        <?php
                        echo $goods_list[$i]['goods_price'];
                        ?>
                    </div>
                </section>
                <?php
            }
            ?>
        </section>
        <style>
        ._f4{
            width: 113px;
        }
        </style>
        <section class="f4">
            <?php
            for ($i = 13; $i < -1 && $i < count($goods_list); $i++) {
                ?>
                <section class="item">
                    <div style="height:20px;position:relative;"></div>
                    <div class="_addcart_hover" style="height: 60px;position:absolute;top:-60px;">
                        <div class="_con_add _f4 _addcart" onclick="addcart(<?php echo $goods_list[$i]['goods_id'];?>,1,'addcart_callback')">
                                <i class="icon-plus-sign">

                            </i>
                            <a href="javascript:;">购物袋</a>
                            </div>
                            <div class="_con_add _f4 _collect" onclick="collect_goods(<?php echo $goods_list[$i]['goods_id'];?>,'count','goods_collect')">
                                <i class="icon-star-empty">
                            </i>
                            <a href="javascript:;">收藏</a>
                        </div>
                    </div>
                    <a href="<?php echo urlShop('goods', 'index', array('goods_id' => $goods_list[$i]['goods_id'])); ?>"
                       class="img">
                        <img src="<?php echo thumb($goods_list[$i], 240, 1) ?>" alt="">
                    </a>

                    <div class="name">
                        <p>
                            <b><?php echo $goods_list[$i]['goods_name'] ?></b>
                        </p>

                        <p>
                            <span>
                            <?php
                            echo $goods_list[$i]['goods_jingle'];
                            ?>
                            </span>
                        </p>

                    </div>
                    <div class="price">
                        ￥
                        <?php
                        echo $goods_list[$i]['goods_price'];
                        ?>
                    </div>
                </section>
                <?php
            }
            ?>
            <div class="clear"></div>
        </section>


    </div>
    <style>
        .pagination li a span{
            color:#000;
        }
        .pagination li a:hover span, .pagination li a:active span{
            background-color: #ff6800;
            border-color: #ff6800;
        }
    </style>
    <div class="wrapper mt30 mb30" style="text-align:center;">
        <div class="pagination"> <?php echo $output['show_page']; ?> </div>
    </div>

    <script>
        $('dd.more a').click(function () {
            $(this).parent().prev().toggleClass("height_auto")
        })
        $('.item').hover(function(){
            $(this).addClass('_item_on');
        },function(){
            $(this).removeClass('_item_on');
        })
        /* 加入购物车后的效果函数 */
        function addcart_callback(data){
            $('#bold_num').html(data.num);
            $('#bold_mly').html(price_format(data.amount));
            $('.ncs-cart-popup').fadeIn('fast');
            update_cart_num();
        }
    </script>
    <?php
}
?>